<template>
  <!-- 放置一个图标 -->
  <div>
    <svg-icon :icon-class="isFullscreen ? 'exit-fullscreen' : 'fullscreen'" class="fullscreen" @click="toggleScreen" />
  </div>
</template>

<script>
import screenfull from 'screenfull'
export default {
  name: 'ScreenFull',
  data() {
    return {
      isFullscreen: false
    }
  },
  created() {
    // ESC会改变当前的全屏状态
    // 这个状态值在插件的.isFullScreen属性中
    screenfull.on('change', () => {
      console.log(screenfull.isFullscreen)
      this.isFullscreen = screenfull.isFullscreen
    })
  },
  methods: {
    toggleScreen() {
      console.log(123)
      screenfull.toggle()// 补充数据项
      this.isFullscreen = !this.isFullscreen// 在全屏切换的时候改变他的值
    }
  }
}
</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  color: #fff;
  cursor: pointer;
}
</style>
